package com.lzc.springboot.mapper;

import com.lzc.springboot.domain.ShowDisease;
import org.apache.ibatis.annotations.*;

@Mapper
public interface DiseaseMapper {

  /**
   * 根据病害总表查询相关信息
   * @param tolDiseaseClass
   * @return
   */
  @Select("select * from diseases_total where id=#{tolDiseaseClass}")
  @Results({
          @Result(
                  property = "disease_level",
                  column = "disease_level",
                  javaType = String.class,
                  one = @One(select = "com.lzc.springboot.mapper.DiseaseMapper.findDisLevelByLevelId")
          ),
          @Result(
                  property = "crop_name",
                  column = "crop_class",
                  javaType = String.class,
                  one = @One(select = "com.lzc.springboot.mapper.CropMapper.findCropNameByCropId")
          ),
          @Result(
                  property = "disease_name",
                  column = "disease_class",
                  javaType = String.class,
                  one = @One(select = "com.lzc.springboot.mapper.DiseaseMapper.findDisNameByDisId")
          ),
          @Result(
                  property = "disease_info",
                  column = "disease_class",
                  javaType = String.class,
                  one = @One(select = "com.lzc.springboot.mapper.DiseaseMapper.findDisDetailByDisId")
          ),
          @Result(
                  property = "disease_resolve",
                  column = "disease_class",
                  javaType = String.class,
                  one = @One(select = "com.lzc.springboot.mapper.DiseaseMapper.findDisSolveByDisId")
          ),
  })
  @Options(useCache = false, flushCache = Options.FlushCachePolicy.TRUE)
  ShowDisease findShowInfo(int tolDiseaseClass);

  /**
   * 根据病害等级编号查询等级
   * @param LevelId
   * @return
   */
  @Select("select level from diseases_level where id=#{LevelId}")
  @Options(useCache = false,flushCache = Options.FlushCachePolicy.TRUE)
  String findDisLevelByLevelId(int LevelId);

  /**
   * 根据灾害id查询灾害名称
   * @param DisId
   * @return
   */
  @Select("select disease_name from diseases_detail where id=#{DisId}")
  @Options(useCache = false,flushCache = Options.FlushCachePolicy.TRUE)
  String findDisNameByDisId(int DisId);

  /**
   * 根据灾害id查询灾害详情
   * @param DisId
   * @return
   */
  @Select("select disease_detail from diseases_detail where id=#{DisId}")
  @Options(useCache = false,flushCache = Options.FlushCachePolicy.TRUE)
  String findDisDetailByDisId(int DisId);

  /**
   * 根据灾害id查询灾害解决方案
   * @param DisId
   * @return
   */
  @Select("select solve from diseases_detail where id=#{DisId}")
  @Options(useCache = false,flushCache = Options.FlushCachePolicy.TRUE)
  String findDisSolveByDisId(int DisId);

  /**
   * 根据农作物id查询相关病害信息
   * @param cropId
   * @return
   */
  @Select("select * from diseases_detail where crop_class=#{cropId}")
  @Options(useCache = false,flushCache = Options.FlushCachePolicy.TRUE)
  @Results({
          @Result(property = "id",column = "id"),
          @Result(property = "disease_name",column = "disease_name"),
          @Result(property = "disease_info",column = "disease_detail"),
          @Result(property = "disease_resolve",column = "solve"),
  })
  ShowDisease[] findDisByCropId(int cropId);

  /**
   * 根据用户输入查询相对应灾害的详情
   * @param text
   * @return
   */
  @Select("select * from diseases_detail where disease_name LIKE concat('%',#{text},'%')")
  @Options(useCache = false,flushCache = Options.FlushCachePolicy.TRUE)
  @Results({
          @Result(property = "id",column = "id"),
          @Result(property = "disease_name",column = "disease_name"),
          @Result(property = "disease_info",column = "disease_detail"),
          @Result(property = "disease_resolve",column = "solve"),
          @Result(
                  property = "crop_name",
                  column = "crop_class",
                  javaType = String.class,
                  one = @One(select = "com.lzc.springboot.mapper.CropMapper.findCropNameByCropId")
          ),
  })
  ShowDisease[] findDisByText(String text);
}
